# @summary A short summary of the purpose of this class
#
# A description of what this class does
#
# @example
#   include emiconfig::t1::wn
class emiconfig::t1::wn (
  $resource_group = "lcglhcb",
  )

{
  $wn_pkgs=[
      "wn",
      "umd-release",
      "ca-policy-egi-core",
      "HEP_OSlibs",
      "mjf-torque",
      "apptainer",
      "apptainer-suid",
      "yum-utils",
      "libicu-devel",
  ]
  package{ $wn_pkgs:
    ensure     => "installed",
    require    => Yumrepo['site'],
  }
  file {"/scratch":
    ensure   => "directory",
    owner    => "root",
    group    => "root",
    mode     => '1777'
  }

  sysctl { "user.max_user_namespaces":
    ensure => present,
    value  => "10000",
    comment => "for singularity",
  }

  yumrepo { "condor":
    baseurl => "http://${mirrorserver}/yum/condor/9.0/el${operatingsystemmajrelease}/release",
    descr => "condor",
    enabled => 1,
    gpgcheck => 0,
    priority => 20,
    before   => Yumrepo['site'],
  }



  $condor_pkg = [
    "condor",
    "condor-classads",
    "condor-kbdd",
    "condor-procd",
    "condor-python",
  ]

  package { $condor_pkg:
    ensure  => installed,
    require => Yumrepo['site'],
  } ->

  file {"/etc/condor/config.d/01-startd.conf":
    mode       =>  '0644',
    owner      =>  'root',
    group      =>  'root',
    source     =>  "puppet:///modules/${module_name}/01-startd.conf",
    notify   => Exec['reconfig_condor']
  } ->

  file {"/etc/condor/config.d/02-startd-hard.conf":
    mode       =>  '0644',
    owner      =>  'root',
    group      =>  'root',
    content    =>  template("${module_name}/02-startd-hard.erb"),
    #notify    => Exec['restart_condor']
    #notify     => Exec['reconfig_condor']
  } ->

  file { "/scratch/condor":
    ensure     =>  "directory",
    owner      =>  'condor',
    group      =>  'condor',
    mode       =>  '755'
  } ->

  service { 'condor':
    ensure     => 'running',
    enable     => true,
    hasrestart => true,
    hasstatus  => true,
  }

  exec {'restart_condor':
    command      => "/sbin/service condor restart",
    refreshonly  => true,
    require => Package["condor"],
  }

  exec {'reconfig_condor':
    command      => "/usr/sbin/condor_reconfig",
    refreshonly  => true,
    require => Package["condor"],
  }

}
